from pdfminer.converter import PDFPageAggregator
from pdfminer.layout import *
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfinterp import PDFResourceManager,PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfparser import PDFParser
f=open('g4dbr.pdf','rb')
parser=PDFParser(f)
doc=PDFDocument(parser)
resource=PDFResourceManager()
laparam=LAParams()
device=PDFPageAggregator(resource,laparams=laparam)
interpreter=PDFPageInterpreter(resource,device)
for page in PDFPage.create_pages(doc):
    interpreter.process_page(page)
    layout=device.get_result()
    for out in layout:
        if hasattr(out,'get_text'):
            text=out.get_text()
            print(text)
